import java.util.Arrays;

public class LeetCode557 {

    public static void main(String[] args) {
        String s = "Let's take LeetCode contest";

        System.out.println(reverseWords(s));
    }

    public static String reverseWords(String s) {
        String[] split = s.split(" ");
        for (int i = 0; i < split.length; i++) {
            char[] cs = split[i].toCharArray();
            for (int left = 0, right = split[i].length() - 1; left < right; left++, right--) {
                char temp = cs[left];
                cs[left] = cs[right];
                cs[right] = temp;
            }
            split[i] = String.valueOf(cs);
        }
        StringBuilder sb = new StringBuilder();
        for (String ss : split) {
            sb.append(ss + " ");
        }
        return sb.substring(0, sb.length() - 2);
    }

}
